/* 招聘广场 */
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router'
import { Button, Spin, Form, Input, Table, DatePicker, Modal, Select ,message} from 'antd'
/* 引用接口文档路径 */
import {
    employmentSquareSelect,hideEmployment
} from 'actions/companyManage'

import '../../style/userControl.less'



const FormItem = Form.Item
@Form.create({})
//abc
@connect(
  (state, props) => ({
    config: state.config,
    userInfoList: state.userInfoList,
  })
)
export default class app extends Component {
  constructor(props) {
    super(props)
    this.state = {
      list:"",//基础数据列表
    }
    this.keyword={"advertisePosition":"","company.companyName":""};//搜索关键词
    this.currentNumber = 1;//当前页面
    this.pagesize = 10;//每页条数
  }
  componentDidMount() {
    this.selectList();
  }
  
  selectFn(){//点击搜索按钮
    this.keyword = {
      "advertisePosition":this.props.form.getFieldValue('advertisePosition'),
      "company.companyName":this.props.form.getFieldValue('company'),
    };
    this.currentNumber=1;
    this.selectList();
  }
  selectList(pageNumber){//查询列表
    const datajson = Object.assign({"start":pageNumber||1,"end":this.pagesize}, this.keyword);
    this.currentNumber = pageNumber||1;
    this.props.dispatch(employmentSquareSelect(
      datajson,
      (respose) => {
        this.setState({
          list: respose,
        })
    }))
  }
  hideData(id){
    Modal.confirm({
      content:"确定要隐藏该条信息吗？",
      onOk:()=>{
        this.props.dispatch(hideEmployment(
          {"advertiseId":id},
          (respose) => {
            message.success(respose.respMsg);
            this.selectList();
        }))
      },
      onCancel:()=>{
      }
    })
  }



  columns() {//表格标题
    return [
      {
        title: '招聘编号',
        key: 'advertiseCode',
        dataIndex: 'advertiseCode',
        width: '10%',
      },
      {
        title: '招聘职位',
        dataIndex: 'advertisePosition',
        key: 'advertisePosition',
        width: '10%',
      },
      {
        title: '薪资范围',
        width: '10%',
        render: (text, recordId, index) => 
        <span>{`${text.minSalary}k~${text.maxSalary}k`}</span>,
      },
      {
        title: '所属公司',
        dataIndex: 'companyName',
        key: 'companyName',
        width: '5%',
      },
      {
        title: '职位说明',
        dataIndex: 'positionExplain',
        key: 'positionExplain',
        width: '10%',
      },
      {
        title: '状态',
        dataIndex: 'positionStatus',
        key: 'positionStatus',
        width: '10%',
        render: (text, recordId, index) => 
        <span>{text==1?'已发布':'已隐藏'}</span>,
      },
      {
        title: '操作',
        width: '10%',
        render: (text, recordId, index) => 
        <div>
          {
            text.positionStatus == 1 ?
            <Button key="seeinfo" type="primary" size="small" onClick={this.hideData.bind(this,text.id)} style={{marginRight:"5px",marginBottom:"5px"}}>隐藏</Button>          
            :
            <span>已隐藏</span>
          }
        </div>
      },
    ]
  }
  


  render () {
    const { getFieldDecorator } = this.props.form    
    const respData = this.state.list.respData ? this.state.list.respData : [];//刷新页面调用接口数据赋值
    return (
      <div className="page">
        {/* 搜索条件筛选块 */}
        <div className="searcDiv">
          <Form onSubmit={this.selectFn.bind(this)} layout="inline">
            <FormItem label="招聘职位">
              {
                getFieldDecorator('advertisePosition', {
                  rules: [{
                    required: false,
                  }],
                })(
                  <Input placeholder="请输入关键字" size="default" style={{ width: '200px' }} />
                )
              }  
            </FormItem>
            <FormItem label="所属公司">
              {
                getFieldDecorator('company', {
                  rules: [{
                    required: false,
                  }],
                })(
                  <Input placeholder="请输入关键字" size="default" style={{ width: '200px' }} />
                )
              }  
            </FormItem>
            <Button type="primary" onClick={this.selectFn.bind(this)}>搜索</Button>
          </Form>
        </div>
        {/*数据渲染列表*/}
        <Spin spinning={false}>
          <Table
            rowKey="id" 
            columns={this.columns()}//表格标题列
            dataSource={respData.resultData}
            pagination={{ total: respData.count, current:this.currentNumber,pageSize: this.pagesize, onChange: this.selectList.bind(this)}}
            scroll={{ y: true }}
          />
        </Spin>

      </div>
    )
  }
}
